package com.qf.ssm.controller;

import com.qf.ssm.entity.FrontCategoryFirst;
import com.qf.ssm.service.FrontCategoryFirstService;
import com.qf.ssm.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/categoryFirst")
public class FrontCategoryFirstController {
    @Resource
    private FrontCategoryFirstService frontCategoryFirstService;

    /**
     * 删除一条一级类目--------展示
     *测试通过，测试内容：
     * {
     *   "fcfId": 14
     * }
     */
    @PutMapping("/deleteCategory")
    private ResponseResult<Integer> deleteCategory(Integer fcfId) {
        return ResponseResult.success(frontCategoryFirstService.deleteByPrimaryKey(fcfId));
    }

    /**
     * 编辑一级类目-----------展示
     *测试通过，测试内容：
     *{
     *   "fcfId": 13,
     *   "fcfName": "demoData",
     *   "status": 1
     * }
     */
    @PutMapping("/editCategory")
    private ResponseResult<Integer> editCategory(@RequestBody FrontCategoryFirst frontCategoryFirst) {
        return ResponseResult.success(frontCategoryFirstService.updateByPrimaryKey(frontCategoryFirst));
    }

    /**
     * 新建一级类目---------展示
     *测试通过，测试内容：
     *{
     *   "fcfName": "日式风格",
     *   "status": 1
     * }
     */
    @PostMapping("/newCategory")
    private ResponseResult<Integer> newCategory(@RequestBody FrontCategoryFirst frontCategoryFirst) {
        return ResponseResult.success(frontCategoryFirstService.insert(frontCategoryFirst));
    }

    /**
     * 批量新建一级类目------不展示
     *
     * @param list
     * @return
     */
    @PostMapping()
    private ResponseResult<Integer> batchNewCategory(@RequestBody List<FrontCategoryFirst> list) {
        return ResponseResult.success(frontCategoryFirstService.batchInsert(list));
    }

    /**
     * 一对多展示二级类目------展示
     * 测试通过，测试内容：
     * {
     *   "fcfId": 2
     * }
     */
    @GetMapping("/queryFirstAndTwo")
    private ResponseResult<FrontCategoryFirst> queryFirstAndTwo(int fcfId) {
        return ResponseResult.success(frontCategoryFirstService.selectFirstAndTwo(fcfId));
    }

    /**
     * 通过分类名称查看商品-----展示
     * 测试通过，测试内容：
     * {
     *   "fcfName": "11"
     * }
     */
    @GetMapping("/queryFirstAndCommodity")
    private ResponseResult<FrontCategoryFirst> queryFirstAndCommodity(String fcfName) {
        return ResponseResult.success(frontCategoryFirstService.selectFirstAndCommodity(fcfName));
    }

    /**
     * 批量删除一级类目-------展示
     * 测试通过，测试内容：
     * {
     *   "fcfIds": [13,15]
     * }
     */
    @PutMapping("/batchDeleteCategory")
    private ResponseResult<Integer> batchDeleteCategory(int[] fcfIds) {
        return ResponseResult.success(frontCategoryFirstService.batchDeleteCategory(fcfIds));
    }

}
